//
//  BaseViewController.m
//  YuanHeLife
//
//  Created by cnmobi on 15-4-17.
//  Copyright (c) 2015年 CNMOBI. All rights reserved.
//

#import "BaseViewController.h"

@interface BaseViewController ()

@end

@implementation BaseViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.backgroundColor = [UIColor whiteColor];
    
    self.naviBar = self.navigationController.navigationBar;
    
    self.navigationController.interactivePopGestureRecognizer.delegate = self;

    

    [self baseCtlSetLeftBtnImage:[UIImage imageNamed:@"back"] andRightBtnImage:nil];
    
    [self.leftNavgationItem setAction:@selector(backVC)];

}

- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:YES];
    
    [self.view endEditing:YES];
}

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    [self.view endEditing:YES];
}

-(void)baseCtlSetTitle:(NSString *)titleStr
{
    if (titleStr) {
        
        UILabel *customLab = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 100, 44)];
        customLab.textAlignment = NSTextAlignmentCenter;
        [customLab setTextColor:[UIColor whiteColor]];
        [customLab setText:titleStr];
        customLab.font = [UIFont boldSystemFontOfSize:19];
        self.navigationItem.titleView = customLab;
    }
    
}


#pragma mark - method
-(void)baseCtlSetLeftBtnImage:(UIImage *)leftImage andRightBtnImage:(UIImage *)rightImage
{
    
    if (leftImage) {
        
        self.leftNavgationItem = [[UIBarButtonItem alloc]initWithImage:leftImage style:UIBarButtonItemStylePlain target:self action:nil];
        self.leftNavgationItem.imageInsets = UIEdgeInsetsMake(0, -8, 0, 8);
        
        self.leftNavgationItem.tintColor = [UIColor whiteColor];
        //        ,[[UIBarButtonItem alloc]initWithTitle:@"" style:UIBarButtonItemStylePlain target:nil action:nil]
        self.navigationItem.leftBarButtonItems = @[self.leftNavgationItem,[[UIBarButtonItem alloc]initWithTitle:@"" style:UIBarButtonItemStylePlain target:nil action:nil]];
        
    }
    if (rightImage) {
        self.rightNavgationItem = [[UIBarButtonItem alloc]initWithImage:rightImage style:UIBarButtonItemStylePlain target:self action:nil];
        self.rightNavgationItem.imageInsets = UIEdgeInsetsMake(0, -10, 0, 10);
        
        self.rightNavgationItem.tintColor = [UIColor whiteColor];
        
        self.navigationItem.rightBarButtonItems =  @[self.rightNavgationItem,[[UIBarButtonItem alloc]initWithTitle:@"" style:UIBarButtonItemStylePlain target:nil action:nil]];;
        
    }
}
-(void)baseCtlSetLeftBtnTitle:(NSString *)leftTitle andWithRightTitle:(NSString *)rightTitle
{
    if (leftTitle) {
        
        _leftNavgationItem = [[UIBarButtonItem alloc]initWithTitle:leftTitle style:UIBarButtonItemStylePlain target:self action:nil];
        
        [_leftNavgationItem setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIFont boldSystemFontOfSize:14], NSFontAttributeName,nil] forState:UIControlStateNormal];
        
        self.leftNavgationItem.tintColor = [UIColor whiteColor];
        self.navigationItem.leftBarButtonItems = @[self.leftNavgationItem,[[UIBarButtonItem alloc]initWithTitle:@"" style:UIBarButtonItemStylePlain target:nil action:nil]];
        
    }
    if (rightTitle) {
        
        _rightNavgationItem = [[UIBarButtonItem alloc]initWithTitle:rightTitle style:UIBarButtonItemStylePlain target:self action:nil];
        [_rightNavgationItem setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIFont boldSystemFontOfSize:14], NSFontAttributeName,nil] forState:UIControlStateNormal];
        
        self.rightNavgationItem.tintColor = [UIColor whiteColor];
        self.navigationItem.rightBarButtonItems =  @[self.rightNavgationItem,[[UIBarButtonItem alloc]initWithTitle:@"" style:UIBarButtonItemStylePlain target:nil action:nil]];
        
        
    }
}

#pragma mark - EVENTS
- (void)backVC
{
    [self.navigationController popViewControllerAnimated:YES];
}


@end
